package com.example.meitao.ui;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.example.meitao.R;

public class SplashActivity extends AppCompatActivity {

    private ImageView iv1,iv2,iv3,iv4;

    private Handler mHandler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            startActivity(new Intent(SplashActivity.this,MainActivity.class));
            finish();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        initView();
        doPlaySequentiallyAnimator();


    }

    private void doPlaySequentiallyAnimator() {
        ObjectAnimator animator1 = ObjectAnimator.ofFloat(iv1, "alpha", 0, 1);
        ObjectAnimator animator2 = ObjectAnimator.ofFloat(iv2, "alpha", 0, 1);
        ObjectAnimator animator3 = ObjectAnimator.ofFloat(iv3, "alpha", 0, 1);
        ObjectAnimator animator4 = ObjectAnimator.ofFloat(iv4, "alpha", 0, 1);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playSequentially(animator1,animator2,animator3,animator4);
        animatorSet.setDuration(1000);
        animatorSet.start();
        mHandler.sendEmptyMessageDelayed(1,4000);
    }

    private void initView() {
        getSupportActionBar().hide();
        iv1 = (ImageView)findViewById(R.id.iv_1);
        iv2 = (ImageView)findViewById(R.id.iv_2);
        iv3 = (ImageView)findViewById(R.id.iv_3);
        iv4 = (ImageView)findViewById(R.id.iv_content);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if(hasFocus&&Build.VERSION.SDK_INT>=19) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    |View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    |View.SYSTEM_UI_FLAG_FULLSCREEN
                    |View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
            );
        }
    }

}
